/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.form;

import com.hitechbangla.fctu.base.GameScene;
import com.hitechbangla.fctu.base.Location;
import com.hitechbangla.fctu.base.weather.CloudShape;
import com.hitechbangla.fctu.base.weather.CloudType;
import com.hitechbangla.fctu.base.weather.RandomCloud;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.Random;

/**
 *
 * @author ASUS
 */
public class AddCloud extends javax.swing.JDialog {

    /**
     * Creates new form AddCloud
     */
    private GameScene gameScene;
    private Point2D point;
    private RandomCloud randomCloud;
    
    
    
    public AddCloud() {
        
    }
    
    public AddCloud(GameScene gameScene, Point2D point) {
        this.gameScene = gameScene;
	this.point = point;	
	this.setLocation(MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y);
        
        initComponents();
        this.pack();
        this.repaint();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldLocationX = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldLocationY = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldLocationZ = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setText("Shape");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(30, 30, 30, 14);

        jLabel2.setText("Type");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(30, 70, 24, 14);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Circular", "Rectangular" }));
        getContentPane().add(jComboBox1);
        jComboBox1.setBounds(80, 30, 100, 20);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mild", "Strong", "Weak" }));
        getContentPane().add(jComboBox2);
        jComboBox2.setBounds(80, 70, 100, 20);

        jButton1.setText("Add");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(70, 270, 73, 23);

        jLabel5.setText("Location (x):");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(20, 110, 61, 14);

        jTextFieldLocationX.setEditable(false);
        getContentPane().add(jTextFieldLocationX);
        jTextFieldLocationX.setBounds(100, 110, 80, 20);

        jLabel6.setText("Location (y):");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(20, 150, 61, 14);

        jTextFieldLocationY.setEditable(false);
        getContentPane().add(jTextFieldLocationY);
        jTextFieldLocationY.setBounds(100, 150, 80, 20);

        jLabel8.setText("Location (z):");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(20, 190, 80, 20);
        getContentPane().add(jTextFieldLocationZ);
        jTextFieldLocationZ.setBounds(100, 190, 80, 20);

        jLabel3.setText("Dimension:");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(20, 220, 70, 20);
        getContentPane().add(jTextField1);
        jTextField1.setBounds(100, 220, 80, 20);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        Location location = new Location(Float.parseFloat(jTextFieldLocationX.getText()) *gameScene.HTBParent.one_nm_equivalent_pixel , Float.parseFloat(jTextFieldLocationY.getText()) * gameScene.HTBParent.one_nm_equivalent_pixel, Float.parseFloat(jTextFieldLocationZ.getText()));
        //Graphics2D g2 = (Graphics2D)g;

      Random generator = new Random();

      int cloud_size = Integer.parseInt(jTextField1.getText());
      RandomCloud randomCloud = new RandomCloud(cloud_size);
      randomCloud.setLocation(location);
      
      for (int i = 0; i < cloud_size; i++)
      {  
      
         double x = location.getX() + 100 * generator.nextDouble();
         double y = location.getY() + 100 * generator.nextDouble();
         
         randomCloud.add(new Point2D.Double(x, y));
      }
        
        gameScene.cloudSystemList.add(randomCloud);
        this.setVisible(false);
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private CloudType getSelectedCloudType()
    {
        switch(jComboBox2.getSelectedIndex()) 
        {
            case 1: return CloudType.MILD;
            case 2: return CloudType.STRONG;
            case 3: return CloudType.WEAK;
            default: return CloudType.WEAK;
        }
    }
    
    private CloudShape getSelectedCloudShape()
    {
        switch(jComboBox1.getSelectedIndex()) 
        {
            case 1: return CloudShape.CIRCULAR;
            case 2: return CloudShape.RETENGULAR;
            default: return CloudShape.CIRCULAR;
        }
        
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AddCloud.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AddCloud.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AddCloud.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AddCloud.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddCloud().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextFieldLocationX;
    private javax.swing.JTextField jTextFieldLocationY;
    private javax.swing.JTextField jTextFieldLocationZ;
    // End of variables declaration//GEN-END:variables
}
